<?php

require_once('../../includes/classes/core.php');
$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count = 		$_REQUEST['count'];
		$hidden = 		$_REQUEST['hidden'];
		$start		= $_REQUEST['start'];
		$end		= $_REQUEST['end'];
	  	$rResult = mysql_query("SELECT  incomming_call.id,
                                        incomming_call.call_date,
                                        incomming_call.call_phone,
                                        cat.`name`,
                                        cat_type.`name`,
                                        object.`name`,
                                        call_content,
                                        persons.`name` 
                                FROM    incomming_call
                                LEFT JOIN category as cat ON incomming_call.category_parent_id = cat.id
                                LEFT JOIN category as cat_type ON incomming_call.category_id = cat_type.id
                                LEFT JOIN object ON incomming_call.call_object_id = object.id
	  	                        JOIN users ON incomming_call.user_id = users.id
	  	                        JOIN persons ON users.person_id = persons.id
                                WHERE incomming_call.actived = 1 AND DATE(incomming_call.call_date)>='$start' AND DATE(incomming_call.call_date)<='$end' AND users.group_id = 3");
	  
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>